home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 227_01 / ega.c < prev    next >
Text File  |  1988-02-07  |  3KB  |  122 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3.  
  4. #define NOLLHINC
  5.  
  6. #include "ega.h"
  7. #include "graphics.h"
  8.  
  9. int gpage;                                  /* current graphics page */
  10. int vidbase = 0xa000;
  11.  
  12. #ifdef USEVOID
  13. void
  14. #endif
  15. setmode(mode)
  16. int mode;
  17. /**
  18. * name          setmode
  19. *
  20. * synopsis      setmode(mode);
  21. *               int mode           video-mode
  22. *
  23. * description   This routine switches to the given video-mode.
  24. *               For valid values see the BIOS video mode tables.
  25. **/
  26. {
  27. union REGS regs;
  28.  
  29. regs.h.ah = 0;     /* action: set mode */
  30. regs.h.al = mode;
  31. int86(0x10, ®s, ®s);
  32. gpage = 0;         /* currently graphics page zero! */
  33. vidbase = 0xa000;
  34. }
  35.  
  36.  
  37.  
  38. getpixel(x, y)
  39. int x, y;
  40. /**
  41. * name          getpixel
  42. *
  43. * synopsis      getpixel(x, y);
  44. *               int x, y    pixel coordinate
  45. *
  46. * description   This routine reads the color of the specified pixel.
  47. *               The color is return as function return value.
  48. **/
  49. {
  50. union REGS regs;
  51.  
  52. regs.h.ah = 0xd;     /* action: set pixel */
  53. regs.h.bh = gpage;
  54. regs.x.cx = x;
  55. regs.x.dx = y;
  56. int86(0x10, ®s, ®s);
  57. return((int) regs.h.al);
  58. }
  59.  
  60.  
  61. #ifdef USEVOID
  62. void
  63. #endif
  64. selpage(pgnr)
  65. int pgnr;
  66. /**
  67. * name          selpage
  68. *
  69. * synopsis      selpage(pgnr);
  70. *               int pgnr
  71. *
  72. * description   This routine allows the selection of the active video page.
  73. *               Note that the number of available pages depends on the
  74. *               video mode (color / monochrome graphics) and the amount of
  75. *               available memory (64, 128 or 256 Kb)!
  76. **/
  77. {
  78. union REGS regs;
  79.  
  80. regs.h.ah = 5;       /* action: select active page */
  81. regs.h.al = pgnr;
  82. int86(0x10, ®s, ®s);
  83. gpage = pgnr;
  84. vidbase = pgnr ? 0xb000 : 0xa000;
  85. }
  86.  
  87.  
  88. #ifdef USEVOID
  89. void
  90. #endif
  91. clrgraph(dummy)
  92. int dummy;
  93. /**
  94. * name          clrgraph
  95. *
  96. * synopsis      clrgraph(dummy)
  97. *               int dummy   no meaning, only for compitibility with herc-lib
  98. *
  99. * description   This routine clears the current graphics-page. Because there
  100. *               is no "graphics clear screen", it first get the actuall video
  101. *               mode and then switches back to that mode. The mode switch
  102. *               includes a clear-screen.
  103. *               The current version of this routine clears always video page
  104. *               zero - if it is the current page or not!
  105. *               The dummy argument is included only for compatibility with the
  106. *               hercules-modules.
  107. **/
  108. {
  109. union REGS regs;
  110.  
  111. regs.h.ah = 0x0f;        /* action: read current video mode */
  112. int86(0x10, ®s, ®s);
  113. regs.h.ah = 0x00;        /* action: set video mode (and clear screen!) */
  114. int86(0x10, ®s, ®s);
  115. if(gpage)                /* current page other than page zero? */
  116.   {                      /* Yes, must switch! */
  117.   regs.h.ah = 0x05;      /* action: select vido page */
  118.   regs.h.al = gpage;     /* libraries page */
  119.   int86(0x10, ®s, ®s);
  120.   }
  121. }
  122.